using System;
using System.Collections.Generic;
using System.Data.Entity;
using Loading.Models;

namespace Com.MasterCard.Loading.AT {
    public class SmartDataSeedingInitializer : DropCreateDatabaseAlways<LoadingContext> {


        protected override void Seed(LoadingContext context) {
            base.Seed(context);
            var bulletSet = context.Set<Bullet>();
            var brassLotSet = context.Set<BrassLot>();
            var CartrigeRecipieSet = context.Set<CartrigeRecipie>();

            var lotA = new BrassLot {
                Name = "Lot a",
                Source = "Initial Brass"
            };
            brassLotSet.Add(lotA);


            var graf158 = new Bullet {
                Calibres = new List<Calibre>{
                    new Calibre{Name = ".38"},
                    new Calibre{Name=".357"}
                },
                Name = "158 grain JHP 38/357"
            };
            bulletSet.Add(graf158);


            var lyman357 = new CartrigeRecipie {
                Powder = new Powder {
                    Vendor = new PowderVendor {
                        Name = "Allient"
                    },
                    Name = "2400"
                },
                Bullet = graf158,
                Primer = new Primer {
                    Name = "CCI SMall Pistol Magnum"
                },
                PowderGrains = 11.3,
                Name = "Lymen357 11.3 grains"


            };
            CartrigeRecipieSet.Add(lyman357);
            

            var lyman38 = new CartrigeRecipie {
                Powder = new Powder {
                    Vendor = new PowderVendor {
                        Name = "ACME"
                    },
                    Name = "Wile E. Coyote's Favorite"
                },
                Bullet = graf158,
                Primer = new Primer {
                    Name = "CCI Small Pistol"
                },
                PowderGrains = 7.8,
                Name = "Lymen38 7.8 grains"
            };
            CartrigeRecipieSet.Add(lyman38);

            var cartrigeLots = new List<CartrigeLot>{
                new CartrigeLot {
                    Brass = new BrassLot {
                        ParentLot = lotA,
                        Name = "Lot a1",
                        Source = "Split lota ",
                        TimesFired = 1   
                    },
                    Count = 38,
                    Name = "c1",
                    CartrigeRecipie = lyman357,
                    Notes = new List<Note> {
                        new Note{
                            TimeStamp = new DateTime(2011,11,5),
                            IsFieldNote = true,
                            Text = "5 misfires"
                        }
                    }
                },
                new CartrigeLot {
                    Brass = new BrassLot {
                        ParentLot = lotA,
                        Name = "Lot a2",
                        Source = "Split lota ",
                        TimesFired = 1
                    },
                    Count = 45,
                    Name = "c2",
                    CartrigeRecipie = lyman357,
                    Notes = new List<Note> {
                        new Note{
                            TimeStamp = new DateTime(2011,11,5),
                            IsFieldNote = true,
                            Text = "2 misfires"
                        },
                        new Note{
                            TimeStamp = new DateTime(2011,11,15),
                            IsFieldNote = true,
                            Text = "2 misfires"
                        }
                    }

                },
                new CartrigeLot {
                    Brass = new BrassLot {
                        Name = "LotB",
                        Source = "Initial 38 rounds",
                        TimesFired = 1
                    },
                    Count = 50,
                    Name = "c38l1",
                    CartrigeRecipie = lyman38,

                }
            };
            cartrigeLots.ForEach(cl => context.CartrigeLots.Add(cl));
            
        }
    }
}
